package com.xianyun.book.controller;

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.xianyun.book.api.OrderServiceI;
import com.xianyun.book.dto.BookIdleRefreshCmd;
import com.xianyun.book.dto.BookPurchaseCmd;
import com.xianyun.book.dto.BookSellAddCmd;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单域
 * @author ytt
 */
@RestController
public class OrderController {

    @Autowired
    private OrderServiceI orderService;

    /**
     * 卖书
     * @return 响应结果
     */
    @PostMapping("/sell")
    public Response addBookOrder(@RequestBody BookSellAddCmd bookSellAddCmd){
        bookSellAddCmd.setIsbn(bookSellAddCmd.getIsbn().replace('-',' ')
                    .replaceAll(" +",""));
        return orderService.postIdle(bookSellAddCmd);
    }

    /**
     * 修改销售订单
     * @param refreshCmd 刷新订单
     * @return 响应结果
     */
    @PostMapping("/sell/edit")
    public Response editBookOrder(@RequestBody BookIdleRefreshCmd refreshCmd){
        return orderService.refreshIdle(refreshCmd);
    }

    /**
     * 买书
     * @return 响应结果
     */
    @PostMapping("/buy")
    public SingleResponse<String> buy(@RequestBody BookPurchaseCmd purchaseCmd){
        purchaseCmd.setIsbn(purchaseCmd.getIsbn().replace('-',' ')
                .replaceAll(" +",""));
        return  orderService.purchaseBook(purchaseCmd);
    }

    /**
     * 获取本用户当前在售书籍
     * @param userSecurity
     * @return 响应结果
     */
    @PostMapping("/book/in/sell/list")
    public MultiResponse<String> getInSellBooks(String userSecurity){
        return MultiResponse.buildSuccess();
    }

    /**
     * 获取本用户当前以售书籍
     * @param userSecurity
     * @return 响应结果
     */
    @PostMapping("/book/have/sell/list")
    public MultiResponse<String> getOffSellBooks(String userSecurity){
        return MultiResponse.buildSuccess();
    }

    /**
     * 获取本用户当前已购书籍
     * @param userSecurity
     * @return 响应结果
     */
    @PostMapping("/book/have/bug/list")
    public MultiResponse<String> getHavePurchaseBooks(String userSecurity){
        return MultiResponse.buildSuccess();
    }


    /**
     * 获取订单信息
     * @param orderId 订单编号
     * @return 详情
     */
    @GetMapping("/book/order/info/{orderId}")
    public SingleResponse<String> getBookOrderInfo(@PathVariable String orderId){
        return SingleResponse.buildSuccess();
    }

    /**
     * 订单状态修改
     * @return 请求结果
     */
    @PostMapping("/book/order/update")
    public Response orderStatusUpdate(){
        return Response.buildSuccess();
    }

    /**
     * 订单评价
     * @return 订单评价结果
     */
    @GetMapping("/book/order/score/submit")
    public Response submitSoreInOrder(){
        return Response.buildSuccess();
    }
}
